//
//  CMDBCommitNoteParam.swift
//  CMDB
//
//  Created by 王磊 on 17/4/6.
//  Copyright © 2017年 CMDB. All rights reserved.
//

import UIKit

class CMDBCommitNoteParam: CMDBBasicParamBean {
    
    var title: String = ""
    
    var content: String {
        
        guard contentArr.count != 0 else {
            
            return ""
        }
        return CMDBCommitNoteParam.castContentToString(contentArr)
    }
    
    var contentArr: Array<CMDBNoteContentParam> = []
    
}
extension CMDBCommitNoteParam {
    
    override func URLString() -> String {
        
        return CMDB_Http_Formal_Domain + "/app/trend/\(server_Version)/pubDiary?"
    }
}
extension CMDBCommitNoteParam {
    
    static func castContentToString(arr: Array<CMDBNoteContentParam>) -> String {
        
        let mutable = NSMutableArray()
        
        _ = arr.map({
            
            mutable.addObject($0.keyValues!)
            
        })
        
        let jsonData = try? NSJSONSerialization.dataWithJSONObject(mutable, options: .PrettyPrinted)
        
        guard let jsonTemp = jsonData else {
            
            return ""
        }
        let jsonStr = String(data: jsonTemp,encoding: NSUTF8StringEncoding)
        
        return jsonStr!
    }
}
